﻿@model ProductModel

@using SmartStore.Admin.Models.Catalog;
@using SmartStore.Core.Domain.Catalog;

@if (Model.Id > 0)
{
	<table class="adminContent mb-5">
		<tr>
			<td colspan="2">
				<div class="admin-config-group">
					<div class="head">@T("Common.Options")</div>
				</div>
			</td>
		</tr>
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.HasPreviewPicture)
			</td>
			<td class="adminData">
				@Html.EditorFor(model => model.HasPreviewPicture)
				@Html.ValidationMessageFor(model => model.HasPreviewPicture)
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<div class="admin-config-group">
					<div class="head">@T("Admin.Catalog.Products.Pictures.AddNew")</div>
				</div>
			</td>
		</tr>
		<tr>
			<td class="adminData wide" colspan="2">
				@Html.EditorFor(model => model.AddPictureModel.PictureId, new
				{
					entityId = Model.Id,
					entityType = "Product",
					transientUpload = false,
					album = "catalog",
					multifile = true,
					deleteUrl = Url.Action("ProductPictureDelete", "Product", "Admin"),
					sortUrl = Url.Action("SortPictures", "Product", "Admin"),
					entityAssignmentUrl = Url.Action("ProductMediaFilesAdd", "Product", "Admin"),
					uploadedFiles = Model.ProductMediaFiles as IEnumerable<IMediaFile>,
					typeFilter = "image"
				})
				@Html.ValidationMessageFor(model => model.AddPictureModel.PictureId)
			</td>
		</tr>
	</table>
}
else
{
	<div class="alert alert-danger">
		@T("Admin.Catalog.Products.Pictures.SaveBeforeEdit")
	</div>
}

<script>
		$(function () {
			// Set MainPictureId for product
            $(document).on("click", ".set-main-picture", function (e) {
				var el = $(this).closest('.dz-image-preview');
                var previewContainer = $(this).closest(".preview-container");

				// Insert choosen media file at beginning of the list
				el.insertBefore(previewContainer.find('.dz-image-preview').first());
				previewContainer.trigger("sort", { item: el });

                return false;
			});
		});
</script>